QuickJump: Back
to Library - 1 -
2 - 3
- 4 - 5
- 6 - 7
- 8 - Bonus
One of the most often-misunderstood features of today's cybugs is the
use of the perimeter-scan formula (or one of its many variations), so I
(James) decided to write this short piece to try to unravel the concept
for anyone having difficulties.
Now before you read further, let me just warn you all that this is currently not as useful as it once was. The introduction of cloaking meant that this method could no longer be relied on to detect enemies, and as always, it does not detect any other obstacles like mines or flags.
However, I do think that it still has a part to play where the programmer desperately needs to speed up their cybug.
How it works:
The formula can basically be thought of as a method of calculating the
distance between our cybug and the closest (uncloaked) enemy. It doesn't
give you the distance in exact numbers of squares, but you will soon learn
what the numbers mean.
Each cybug has access to information regarding the enemy's position
(#enemy_x and #enemy_y) and its own position (#x_pos and #y_pos).
also, 'b' is the difference between the x-coordinates:
So if we add these two numbers together, we get a value which gives us an idea of how far the enemy is from our cybug. There is one other complication though - if the value of the enemy's x or y-coordinate is greater than that of our cybug, then the difference will be negative. In many cases where the difference in one direction is large and positive and the difference in the other direction is large and negative, the result of adding these two together will give a small number even though the enemy is nowhere near us.
To account for this, square each of the differences. This eliminates the problem of negative differences because when you square any number, positive or negative, you always get a positive result.
Now the formula is: distance = (#x_pos - #enemy_x)2 + (#y_pos - #enemy_y)2.
The squaring of each of the brackets means that when the enemy is far away, the result can be very large. However, we are normally only going to be interested in when the enemy is quite close, and at these time the numbers are quite manageable.
The following table lists the result of the calculation in situations when the enemy is quite close to our cybug. We are in the center square (shown as '0' and highlighted in green) and the number in each of the other squares is the result of the calculation for a closest enemy in that position. Makes sense? If not, have a look anyway coz it took ages to calculate :-)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From this table, it can be seen that if an enemy is in any of the spaces directly next to our cybug (shown in blue), the result of the calculation will be 1 or 2. Therefore, it has become normal to do the calculation and then check for the result being less than 3. for example:
QuickJump: Back to Library - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - Bonus